package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.SalesTop10ReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin/report")
@Api(value = "管理端图形化")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 营业额统计接口
     * @param begin
     * @param end
     * @return
     */
    @ApiOperation("营业额统计接口")
    @GetMapping("/turnoverStatistics")
    public Result turnoverStatistics(@DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate begin,
                                     @DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate end){
        return reportService.turnoverStatistics(begin,end);
    }
    /**
     * 用户统计接口
     * @param begin
     * @param end
     * @return
     */
    @ApiOperation("营业额统计接口")
    @GetMapping("/userStatistics")
    public Result userStatistics(@DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate begin,
                                     @DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate end){
        return reportService.userStatistics(begin,end);
    }
    /**
     * 订单统计接口
     * @param begin
     * @param endtop10
     * @return
     */
    @ApiOperation("订单统计接口")
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> ordersStatistics(@DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate begin,
                                                  @DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate end){
        return reportService.ordersStatistics(begin,end);
    }
    /**
     * 查询销量排名top10接口
     * @param begin
     * @param end
     * @return
     */
    @ApiOperation("查询销量排名top10接口")
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> topStatistics(@DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate begin,
                                                    @DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate end){
        return reportService.topStatistics(begin,end);
    }
    /**
     * 导出运营数据报表
     * @param response
     * @return
     */
    @ApiOperation("导出运营数据报表")
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        reportService.exportBusinessData(response);
    }
}
